package com.rpc.example.handler;

import com.rpc.example.codec.RpcDecode;
import com.rpc.example.codec.RpcEncode;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.logging.LoggingHandler;

/**
 *
 *
 * @author Elvis
 * @version 1.0, 2022/11/10
 */
public class RpcServerInitHandler extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline()
                .addLast(new LengthFieldBasedFrameDecoder(
                        Integer.MAX_VALUE,
                        12,
                        4,
                        0,
                        0
                ))
                .addLast(new LoggingHandler())
                .addLast(new RpcEncode())
                .addLast(new RpcDecode())
                .addLast(new RpcServerHandler());
    }
}
